<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp"%>
<head>
<title><spring:message code="admin.faqcategory.title" /></title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" href="<c:url value="/css/styles.css"/>" />
<script src="<c:url value="/javascripts/common.js"/>"></script>

</head>

<body><%@include file="../top_menu.jsp"%>
<table width="100%">
	<tr>
		<td><c:import url="/WEB-INF/jsp/admin/faq/faq_menu.jsp" /></td>
	</tr>
</table>
<c:if test="${not empty listCategories}">
	<table class="formTable" width="70%" cellspacing="0">
		<tr class="ui-state-default">
			<c:if test="${listCategories.pageNumber>1}">
				<td align="left"><a
					href="faq_category.htm?pageNo=${listCategories.pageNumber-1}&sortColumn=${listCategories.sortColumn}"
					class="mouseEffect"><span class="ui-icon ui-icon-seek-prev"
					style="float: left;"></span><spring:message code="admin.faqcategory.button.previouspage" /></a></td>
			</c:if>
			<c:if
				test="${listCategories.pageNumber<listCategories.pagesAvailable}">
				<td align="right"><a
					href="faq_category.htm?pageNo=${listCategories.pageNumber+1}&sortColumn=${listCategories.sortColumn}"
					class="mouseEffect"><span class="ui-icon ui-icon-seek-next"
					style="float: right;"></span><spring:message code="admin.faqcategory.button.nextpage" /></a></td>
			</c:if>
		</tr>
	</table>
	<table class="formTable" width="70%">
		<tr class="formHeader">
			<td colspan="9"><spring:message code="admin.faqcategory.label.questioncategories" /></td>
		</tr>
		<tr class="formSubHeader">
			<th>#</th>
			<th><spring:message code="admin.faqcategory.label.name" /></th>
			<th align="center" colspan="2" align="center"><spring:message code="admin.faqcategory.label.actions" /></th>
		</tr>

		<c:forEach var="cat" items="${listCategories.pageItems}" varStatus="i">
			<tr class="tr_record">
				<td>${i.count+(listQuestions.recordSize*(listCategories.pageNumber-1))}</td>
				<td><input type="text" id="txtCatName_${cat.id}" maxlength="256"
					value="${cat.name}" size="50" /></td>
				<td><input type="button"
					class='ui-button ui-state-default ui-corner-all' value="<spring:message code="admin.faqcategory.button.update" />"
					onclick="updateCategory('${cat.id}')" />
				</td>
				<td>
				<input
					type="button" class='ui-button ui-state-default ui-corner-all'
					value="<spring:message code="admin.faqcategory.button.delete" />" onclick="deleteCategory('${cat.id}')" /></td>
					
			</tr>
		</c:forEach>
	</table>
	<table class="formTable" width="70%" cellspacing="0">
		<tr class="ui-state-default">
			<c:if test="${listCategories.pageNumber>1}">
				<td align="left"><a
					href="faq_category.htm?pageNo=${listCategories.pageNumber-1}&sortColumn=${listCategories.sortColumn}"
					class="mouseEffect"><span class="ui-icon ui-icon-seek-prev"
					style="float: left;"></span><spring:message code="admin.faqcategory.button.previouspage" /></a></td>
			</c:if>
			<c:if
				test="${listCategories.pageNumber<listCategories.pagesAvailable}">
				<td align="right"><a
					href="faq_category.htm?pageNo=${listCategories.pageNumber+1}&sortColumn=${listCategories.sortColumn}"
					class="mouseEffect"><span class="ui-icon ui-icon-seek-next"
					style="float: right;"></span><spring:message code="admin.faqcategory.button.nextpage" /></a></td>
			</c:if>
		</tr>
	</table>
</c:if>

<table width=70% class="formTable">

	<tr class="formHeader">

		<td colspan="5"><spring:message code="admin.faqcategory.label.addnewcategory" /></td>
	</tr>
	<form:form commandName="newCategory" method="post"
		onsubmit="return validateForm()">
		<tr>
			<td>&nbsp;</td>
			<td><form:input path="name" size="50" maxlength="256" /></td>
			<td>&nbsp;&nbsp;&nbsp;&nbsp; <input type=submit value="<spring:message code="admin.faqcategory.button.save" />" />&nbsp;&nbsp;&nbsp;&nbsp;
			</td>
		</tr>
	</form:form>
	<tr>
		<td>&nbsp;</td>
	</tr>
</table>
<%@include file="/WEB-INF/jsp/include/footer.jsp"%>
<script language="javascript">
	function updateCategory(id) {
		var nameField = document.getElementById('txtCatName_' + id);
		if(validate_required(nameField,'Please enter category name')){
			if (validate_length(nameField, 'Category name', 255)) {
				var updateUrl = "update_category.htm?id=" + id;
				updateUrl += "&name=" + nameField.value;
				window.location = updateUrl;			
			}
		}
	}
	
	function deleteCategory(id) {
		if (confirm('Are you sure you want to delete this category?')) {
			var deleteUrl = "delete_category.htm?id=" + id;
			window.location = deleteUrl;
		}
	}
	 function validateForm(){
		var isValid = true;
		var nameField = document.getElementById("name");
		isValid = validate_required(nameField,'Please enter category name');
		
		if (isValid) {
			isValid = validate_length(nameField, 'Category name', 255);
		}
		
		return isValid;		
	 }
</script>
</body>
</html>